<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var str = "今天的天气真不错!";
        var str1 = '';
        for (var i = 0; i < str.length; i++) {
            var s1 = str[i]; // 获取得到每个字符
            if (s1 == '天' && str[i + 1] == '气') {
                //console.log('找到了天')
                str1 += '*';
                i++;
            } else {
                str1 += s1;
            }
        }
        console.log(str1);
    </script>
</body>

</html>